Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(agent_install): only install required packages [SMAGENT-6558] #465

Merged
merged 11 commits into from
Apr 19, 2024

Conversation

iurly
Copy link
Contributor

@iurly iurly commented Apr 8, 2024

rework the role so to only install the packages required by the
selected driver (and therefore, the respective dependencies).
Also, remove packages which are no longer required by the
selected driver type.

Notice we need to craft a list augmented with the selected
version, if one is present.

Most of the selection logic (namely, based on the version)
resides in the 'agent' filter which is probably far from
ideal but gets the job done.

Side changes to make CI pass on this PR:

  • DO NOT delete environment file in case of kmod (otherwise agent 13.1.0 will fail)
  • DO NOT RUN tests on Ubuntu 18.04 (due older systemd not accepting non-absolute path for kill -- otherwise agent 13.1.0 will fail)
  • execute local forwarder test on EC2 instead of container (due to systemd unit)

@iurly iurly force-pushed the gerlando-agent-packages branch 2 times, most recently from 8aefeef to 6ee0707 Compare April 9, 2024 12:42
@iurly iurly changed the title wip: install select packages feat(agent_install): only install required packages [SMAGENT-6558] Apr 9, 2024
@iurly iurly requested review from aroberts87 and mprzybylski and removed request for aroberts87 April 9, 2024 12:43
@iurly iurly marked this pull request as ready for review April 9, 2024 12:58
Comment on lines 42 to 65
all_packages = {
"draios-agent": False,
"draios-agent-slim": False,
"draios-agent-kmodule": False,
"draios-agent-legacy-ebpf": False,
}
if pinned:
version = to_agent_version(data)
minver = LooseVersion("1.0.0")
maxver = LooseVersion("13.1.0")
older = minver < LooseVersion(version) < maxver
if older:
all_packages ["draios-agent"] = True
else:
dt = to_agent_driver_type(data)
if dt == "universal_ebpf":
all_packages ["draios-agent-slim"] = True
elif dt == "legacy_ebpf":
all_packages ["draios-agent-slim"] = True
all_packages ["draios-agent-legacy-ebpf"] = True
else:
all_packages ["draios-agent"] = True
all_packages ["draios-agent-slim"] = True
all_packages ["draios-agent-kmodule"] = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least to me, keying the package map off of the driver type makes things a bit more straight forward. As an example:

package_map = {
  "universal_ebpf": ["draios-agent-slim"],
  "legacy_ebpf": ["draios-agent-slim", "draios-agent-legacy-ebpf"],
  "kmod": ["draios-agent", "draios-agent-slim", "draios'agent-kmodule"]
}
...
if older:
  return ["draios-agent"]
return package_map[to_agent_driver_type(data)]

In this way we don't have to manually "flip the switch" for packages to install for a given driver and also there is a clear mapping between driver type and package.

The to_agent_install_packages() and to_agent_uninstall_packages() methods can be simplified to something like this as well:

to_agent_uninstall_packages()

# hacky global. could make better.
AGENT_PACKAGES = ["draios-agent", "draios-agent-legacy-ebpf", "draios-agent-slim", "draios-agent-kmodule"]
...
def to_agent_uninstall_packages(data):
  return [p for p in AGENT_PACKAGES if p not in to_agent_packages(data)]

to_agent_install_packages(data):

def to_agent_install_packages(data):
  return to_agent_packages(data)

@iurly iurly force-pushed the gerlando-agent-packages branch from 2a3b3c3 to c4080f7 Compare April 16, 2024 22:02
iurly added 6 commits April 18, 2024 16:17
rework the role so to only install the packages required by the
selected driver (and therefore, the respective dependencies).
Also, remove packages which are no longer required by the
selected driver type.

Notice we need to craft a list augmented with the selected
version, if one is present.

Most of the selection logic (namely, based on the version)
resides in the 'agent' filter which is probably far from
ideal but gets the job done.
@iurly iurly force-pushed the gerlando-agent-packages branch from c618a61 to 9e6c06a Compare April 18, 2024 14:19
@iurly iurly force-pushed the gerlando-agent-packages branch from 4c5af01 to 8314750 Compare April 19, 2024 13:57
@iurly iurly force-pushed the gerlando-agent-packages branch from 8314750 to e027784 Compare April 19, 2024 14:20
@iurly iurly enabled auto-merge (squash) April 19, 2024 14:50
@iurly iurly merged commit 6a582c2 into main Apr 19, 2024
8 checks passed
@iurly iurly deleted the gerlando-agent-packages branch April 19, 2024 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants